﻿using LJX.SmartPark.Service.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LJX.SmartPark.Domain.SysManage;
using LJX.SmartPark.Common.ResponseOutput;
using LJX.SmartPark.Service.IotInfo.SmartLamp;
using LJX.SmartPark.Common.Extensions;

namespace LJX.SmartPark.Service.SysManage
{
    public class CategorySrevice:ICategorySrevice
    {
        private readonly IRepository<Category> _CategoryService;

        public CategorySrevice(IRepository<Category> CategoryService)
        {
            _CategoryService = CategoryService;
        }

        public async Task<Response<List<Category>>> GetCategoryPage(SelectLogs select)
        {
            var datas = await _CategoryService.GetAllListAsync();
            var result = datas.MapToList<Category>();
            var totalCount = result.Count();

            result = result.Skip(((select.pageIndex - 1) * select.pageSize)).Take(select.pageSize).ToList();

            return Response<List<Category>>.Ok(result, totalCount);
        }


        public int GetCount()
        {
            return _CategoryService.GetCount();
        }

        public class SelectLogs
        {
            public int pageIndex { get; set; }
            public int pageSize { get; set; }
        }
    }
}
